import { createStore } from "vuex";

export default createStore({
  state: {
    editableTabsValue: "/index",
    editableTabs: [
      {
        title: "首页",
        name: "/index",
      },
    ],
    // 新增：分类选中状态
    selectedTypeId: null,
  },
  getters: {},
  mutations: {
    ADD_TABS: (state, tab) => {
      //选择目录在表单中不存在的时候
      if (
        state.editableTabs.findIndex((item) => item.name === tab.path) === -1
      ) {
        state.editableTabs.push({
          title: tab.name,
          name: tab.path,
        });
      }
      state.editableTabsValue = tab.path;
    },
    RESET_TABS: (state) => {
      //退出登录时需要重置tabs
      (state.editableTabsValue = "/index"),
        (state.editableTabs = [
          {
            title: "首页",
            name: "/index",
          },
        ]);
    },
    // 新增：设置选中分类ID的mutation
    SET_SELECTED_TYPE_ID: (state, id) => {
      state.selectedTypeId = id;
    },
  },
  actions: {},
  modules: {},
});
